package com.gamex.findit.controller.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.gamex.findit.Constants;
import com.gamex.findit.internal.DefaultConfig;
import com.gamex.findit.model.ADImage;
import com.gamex.findit.model.Image;
import com.gamex.findit.model.ImageCut;
import com.gamex.findit.model.Member;
import com.gamex.findit.service.ADImageService;
import com.gamex.findit.service.ImageService;
import com.gamex.findit.util.CommonUtil;
import com.gamex.findit.util.Generator;
import com.mysql.jdbc.StringUtils;

@Controller("adminImage")
public class ImageController {
	
	private static final Logger logger = LoggerFactory.getLogger(ImageController.class);
	
	@Autowired ImageService imageService;
	@Autowired ADImageService adImageService;
	@Autowired DefaultConfig config;
	
	@InitBinder
	public void initBinder(WebDataBinder binder) {
	    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
	
	@RequestMapping("/admin/imageList")
	public String imageList( HttpSession session
			  			   , HttpServletRequest request
						   , HttpServletResponse response
						   , ModelMap model
						   , @ModelAttribute Image image) throws Exception{
	
	List<Image>	result = imageService.getImage(image);
	int count = imageService.getImageCount(image);
	
	model.addAttribute("list",result);
	model.addAttribute("count", count);
	model.addAttribute("pageNo", image.getPageNo());
	model.addAttribute("pageGroup", image.getPageGroup());
	model.addAttribute("searchParam", image);
	
	return "/image/image";
	}

	/**
	 * 이미지 상세보기
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param image
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/imageView")
	public String imageView( HttpSession session
						   , HttpServletRequest request
						   , HttpServletResponse response
						   , Model model
						   , @ModelAttribute ADImage adImage
						   , @ModelAttribute Image image) throws Exception{
	
		// 사용자 아이디
		Member member = (Member) session.getAttribute(Constants.SESSION_INFO);	
		
	//	// 광고가 있는 이미지 인지...
	//	ADImage adImage = new ADImage();
	//	adImage.setImgId(image.getImgId());
	//	ADImage adImageResult = adImageService.getADView(adImage);
	//	if(adImageResult != null)
	//		model.addAttribute("adId", adImageResult.getAdId());
	//	else
	//		model.addAttribute("adId", 0);
		
		model.addAttribute("userId", member.getUserId());
		model.addAttribute("view", imageService.getImageView(image));
		model.addAttribute("sub1", imageService.getImageCut(image.getImgId(), 1));
		model.addAttribute("sub2", imageService.getImageCut(image.getImgId(), 2));
		model.addAttribute("sub3", imageService.getImageCut(image.getImgId(), 3));
		model.addAttribute("sub4", imageService.getImageCut(image.getImgId(), 4));
		model.addAttribute("sub5", imageService.getImageCut(image.getImgId(), 5));
		model.addAttribute("sub6", imageService.getImageCut(image.getImgId(), 6));
		model.addAttribute("sub7", imageService.getImageCut(image.getImgId(), 7));
		model.addAttribute("sub8", imageService.getImageCut(image.getImgId(), 8));
		model.addAttribute("sub9", imageService.getImageCut(image.getImgId(), 9));
		model.addAttribute("sub10", imageService.getImageCut(image.getImgId(), 10));
		
		model.addAttribute("view2", adImageService.getADView(adImage));
		model.addAttribute("searchParam", image);
	return "/image/viewImage";
	}	
	
	/**
	 * 이미지 삭제
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param image
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/imageDelete")
	public String imageDelete( HttpSession session
							  , HttpServletRequest request
							  , HttpServletResponse response
							  , Model model
							  , @ModelAttribute Image image) throws Exception{
		
		imageService.deleteImageCut(image.getImgId());
		imageService.deleteImage(image.getImgId());
		
	return "redirect:/admin/imageList.json";
	}
	
	/**
	 * 이미지 등록 
	 * @param request
	 * @param response
	 * @param image
	 * @param file1
	 * @param file2
	 * @param file3
	 * @param file4
	 * @param file5
	 * @param file6
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/imageInsert")
	public String imageInsert( HttpServletRequest request
							 , HttpServletResponse response
							 , @ModelAttribute Image image
							 , @RequestParam("file")  MultipartFile  file
							 , @RequestParam("file1") MultipartFile  file1
							 , @RequestParam("file2") MultipartFile  file2
							 , @RequestParam("file3") MultipartFile  file3
							 , @RequestParam("file4") MultipartFile  file4
							 , @RequestParam("file5") MultipartFile  file5
							 , @RequestParam("file6") MultipartFile  file6
							 , @RequestParam("file7") MultipartFile  file7
							 , @RequestParam("file8") MultipartFile  file8
							 , @RequestParam("file9") MultipartFile  file9
							 , @RequestParam("file10") MultipartFile  file10
							 , @RequestParam("file11") MultipartFile  file11
							 , @ModelAttribute ADImage adImage
							 , HttpSession session
							 , Model model) throws Exception{

		// 사용자 아이디
		Member member = (Member) session.getAttribute(Constants.SESSION_INFO);	
		image.setUserId(member.getUserId());
		
		int result = 0;
		String name = Generator.generateFileName();
		ImageCut subImage = null;
		if(file1.getSize() > 0){
			CommonUtil.writeImage(request, file1, Constants.DEFAULT_IMG_PATH, name);
			image.setImg(String.format(Constants.DEFAULT_IMG_URL, config.getHostAddress()) + name);
			
		}
			
		result = imageService.insertImage(image);
		
	   //서브 이미지 등록 
	   if(file2.getSize() > 0 && result != 0){
	   	name = Generator.generateFileName();
	   	CommonUtil.writeImage(request, file2, Constants.DEFAULT_SUB_IMG_PATH, name);
	   }
	   
	    subImage = new ImageCut();
		subImage.setImgId(image.getImgId());
		subImage.setX(request.getParameter("cutx1"));
		subImage.setY(request.getParameter("cuty1"));
		subImage.setxSize(request.getParameter("cutxSizex1"));
		subImage.setySize(request.getParameter("cutySizey1"));
		subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		subImage.setSeq(1);
		imageService.insertImageCut(subImage);
		
	  if(file3.getSize() > 0 && result != 0){
	    name = Generator.generateFileName();
	    CommonUtil.writeImage(request, file3, Constants.DEFAULT_SUB_IMG_PATH, name);
	  }
	    subImage = new ImageCut();
		subImage.setImgId(image.getImgId());
		subImage.setX(request.getParameter("cutx2"));
		subImage.setY(request.getParameter("cuty2"));
		subImage.setxSize(request.getParameter("cutxSizex2"));
		subImage.setySize(request.getParameter("cutySizey2"));
		subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		subImage.setSeq(2);
		imageService.insertImageCut(subImage);
		
	  if(file4.getSize() > 0 && result != 0){
	    name = Generator.generateFileName();
	    CommonUtil.writeImage(request, file4, Constants.DEFAULT_SUB_IMG_PATH, name);
	  }
	    subImage = new ImageCut();
		subImage.setImgId(image.getImgId());
		subImage.setX(request.getParameter("cutx3"));
		subImage.setY(request.getParameter("cuty3"));
		subImage.setxSize(request.getParameter("cutxSizex3"));
		subImage.setySize(request.getParameter("cutySizey3"));
		subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		subImage.setSeq(3);
		imageService.insertImageCut(subImage);
		
	  if(file5.getSize() > 0 && result != 0){
	    name = Generator.generateFileName();
	    CommonUtil.writeImage(request, file5, Constants.DEFAULT_SUB_IMG_PATH, name);
	  }
	  
	    subImage = new ImageCut();
		subImage.setImgId(image.getImgId());
		subImage.setX(request.getParameter("cutx4"));
		subImage.setY(request.getParameter("cuty4"));
		subImage.setxSize(request.getParameter("cutxSizex4"));
		subImage.setySize(request.getParameter("cutySizey4"));
		subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		subImage.setSeq(4);
		imageService.insertImageCut(subImage);
		
	  if(file6.getSize() > 0 && result != 0){
	    name = Generator.generateFileName();
	    CommonUtil.writeImage(request, file6, Constants.DEFAULT_SUB_IMG_PATH, name);
	  }
	  
	  	subImage = new ImageCut();
		subImage.setImgId(image.getImgId());
		subImage.setX(request.getParameter("cutx5"));
		subImage.setY(request.getParameter("cuty5"));
		subImage.setxSize(request.getParameter("cutxSizex5"));
		subImage.setySize(request.getParameter("cutySizey5"));
		subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		subImage.setSeq(5);
		imageService.insertImageCut(subImage);
		
	 if(file7.getSize() > 0 && result != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file7, Constants.DEFAULT_SUB_IMG_PATH, name);
		    subImage = new ImageCut();
		    subImage.setImgId(image.getImgId());
		    subImage.setX(request.getParameter("cutx6"));
		    subImage.setY(request.getParameter("cuty6"));
		    subImage.setxSize(request.getParameter("cutxSizex6"));
		    subImage.setySize(request.getParameter("cutySizey6"));
		    subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		    subImage.setSeq(6);
		    imageService.insertImageCut(subImage);		
		  }
		  
		
	 if(file8.getSize() > 0 && result != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file8, Constants.DEFAULT_SUB_IMG_PATH, name);
		    subImage = new ImageCut();
		    subImage.setImgId(image.getImgId());
		    subImage.setX(request.getParameter("cutx7"));
		    subImage.setY(request.getParameter("cuty7"));
		    subImage.setxSize(request.getParameter("cutxSizex7"));
		    subImage.setySize(request.getParameter("cutySizey7"));
		    subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		    subImage.setSeq(7);
		    imageService.insertImageCut(subImage);	
		  }
		  
			
	 if(file9.getSize() > 0 && result != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file9, Constants.DEFAULT_SUB_IMG_PATH, name);
		    subImage = new ImageCut();
		    subImage.setImgId(image.getImgId());
		    subImage.setX(request.getParameter("cutx8"));
		    subImage.setY(request.getParameter("cuty8"));
		    subImage.setxSize(request.getParameter("cutxSizex8"));
		    subImage.setySize(request.getParameter("cutySizey8"));
		    subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		    subImage.setSeq(8);
		    imageService.insertImageCut(subImage);
		  }
		  
			
	 if(file10.getSize() > 0 && result != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file10, Constants.DEFAULT_SUB_IMG_PATH, name);
		    subImage = new ImageCut();
		    subImage.setImgId(image.getImgId());
		    subImage.setX(request.getParameter("cutx9"));
		    subImage.setY(request.getParameter("cuty9"));
		    subImage.setxSize(request.getParameter("cutxSizex9"));
		    subImage.setySize(request.getParameter("cutySizey9"));
		    subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		    subImage.setSeq(9);
		    imageService.insertImageCut(subImage);	
		  }
		  
			
	 if(file11.getSize() > 0 && result != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file11, Constants.DEFAULT_SUB_IMG_PATH, name);
		    subImage = new ImageCut();
		    subImage.setImgId(image.getImgId());
		    subImage.setX(request.getParameter("cutx10"));
		    subImage.setY(request.getParameter("cuty10"));
		    subImage.setxSize(request.getParameter("cutxSizex10"));
		    subImage.setySize(request.getParameter("cutySizey10"));
		    subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress()) + name);
		    subImage.setSeq(10);
		    imageService.insertImageCut(subImage);				
		  }
			
		// 광고
		if(file.getSize() > 0 && !StringUtils.isNullOrEmpty(adImage.getAdName())){
			String name2 = Generator.generateFileName();
			CommonUtil.writeImage(request, file, Constants.DEFAULT_AD_IMG_PATH, name2);
			adImage.setImg(String.format(Constants.DEFAULT_AD_URL, config.getHostAddress()) + name2);
			adImage.setUserId(image.getUserId());
			adImage.setImgId(image.getImgId());
			adImageService.insertAD(adImage);
		}
		
	return  "redirect:/admin/imageView.json?imgId="+image.getImgId();
	}
	
	/**
	 * 이미지 수정
	 * @param request
	 * @param response
	 * @param image
	 * @param file1
	 * @param file2
	 * @param file3
	 * @param file4
	 * @param file5
	 * @param file6
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/imageUpdate")
	public String imageUpdate( HttpServletRequest request
							 , HttpServletResponse response
							 , @ModelAttribute Image image
							 , @RequestParam("file")  MultipartFile  file
							 , @RequestParam("file1") MultipartFile  file1
							 , @RequestParam("file2") MultipartFile  file2
							 , @RequestParam("file3") MultipartFile  file3
							 , @RequestParam("file4") MultipartFile  file4
							 , @RequestParam("file5") MultipartFile  file5
							 , @RequestParam("file6") MultipartFile  file6
							 , @RequestParam("file7") MultipartFile  file7
							 , @RequestParam("file8") MultipartFile  file8
							 , @RequestParam("file9") MultipartFile  file9
							 , @RequestParam("file10") MultipartFile  file10
							 , @RequestParam("file11") MultipartFile  file11
							 , @ModelAttribute ADImage adImage
							 , ModelMap model) throws Exception{

		//메인이미지등록
		int id = image.getImgId();
		ImageCut subImage = null;
		String name = Generator.generateFileName();
		if(file1.getSize() > 0){
			CommonUtil.writeImage(request, file1, Constants.DEFAULT_IMG_PATH, name);
			image.setImg(String.format(Constants.DEFAULT_IMG_URL, config.getHostAddress()) + name);
			
		}
		
		imageService.updateImage(image);
		
	   //서브 이미지 등록 
		subImage = new ImageCut();
	   if(file2.getSize() > 0 && id != 0){
			name = Generator.generateFileName();
			CommonUtil.writeImage(request, file2, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	   }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx1"));
			subImage.setY(request.getParameter("cuty1"));
			subImage.setxSize(request.getParameter("cutxSizex1"));
			subImage.setySize(request.getParameter("cutySizey1"));
			subImage.setSeq(1);
			
		
			imageService.updateImageCut(subImage);
			
			subImage = new ImageCut();
	  if(file3.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file3, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx2"));
			subImage.setY(request.getParameter("cuty2"));
			subImage.setxSize(request.getParameter("cutxSizex2"));
			subImage.setySize(request.getParameter("cutySizey2"));
			subImage.setSeq(2);
			imageService.updateImageCut(subImage);
			
		subImage = new ImageCut();
	  if(file4.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file4, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx3"));
			subImage.setY(request.getParameter("cuty3"));
			subImage.setxSize(request.getParameter("cutxSizex3"));
			subImage.setySize(request.getParameter("cutySizey3"));
			subImage.setSeq(3);
			imageService.updateImageCut(subImage);
		
			subImage = new ImageCut();
	  if(file5.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file5, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }	
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx4"));
			subImage.setY(request.getParameter("cuty4"));
			subImage.setxSize(request.getParameter("cutxSizex4"));
			subImage.setySize(request.getParameter("cutySizey4"));
			subImage.setSeq(4);
			imageService.updateImageCut(subImage);
		
			subImage = new ImageCut();
	  if(file6.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file6, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx5"));
			subImage.setY(request.getParameter("cuty5"));
			subImage.setxSize(request.getParameter("cutxSizex5"));
			subImage.setySize(request.getParameter("cutySizey5"));
			subImage.setSeq(5);                     
			imageService.updateImageCut(subImage);
			
		subImage = new ImageCut();
	  if(file7.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file7, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
			
			
	  }
			
		  subImage.setImgId(id);
		  subImage.setX(request.getParameter("cutx6"));
		  subImage.setY(request.getParameter("cuty6"));
		  subImage.setxSize(request.getParameter("cutxSizex6"));
		  subImage.setySize(request.getParameter("cutySizey6"));
		  subImage.setSeq(6);                     
		  
		  if(hasImaggCut(subImage))
			  imageService.updateImageCut(subImage);				
		  else{ 
			  if(file7.getSize() > 0)
				  imageService.insertImageCut(subImage);
		  }
				
			subImage = new ImageCut();
	  if(file8.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file8, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx7"));
			subImage.setY(request.getParameter("cuty7"));
			subImage.setxSize(request.getParameter("cutxSizex7"));
			subImage.setySize(request.getParameter("cutySizey7"));
			subImage.setSeq(7);                     
			
			if(hasImaggCut(subImage))
				imageService.updateImageCut(subImage);				
			else{ 
				  if(file8.getSize() > 0)
					  imageService.insertImageCut(subImage);
				  }				

			
			subImage = new ImageCut();
	  if(file9.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file9, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx8"));
			subImage.setY(request.getParameter("cuty8"));
			subImage.setxSize(request.getParameter("cutxSizex8"));
			subImage.setySize(request.getParameter("cutySizey8"));
			subImage.setSeq(8);                     
			
			if(hasImaggCut(subImage))
				imageService.updateImageCut(subImage);				
			else{ 
				  if(file9.getSize() > 0)
					  imageService.insertImageCut(subImage);
				  }			

			
				subImage = new ImageCut();
	  if(file10.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file10, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx9"));
			subImage.setY(request.getParameter("cuty9"));
			subImage.setxSize(request.getParameter("cutxSizex9"));
			subImage.setySize(request.getParameter("cutySizey9"));
			subImage.setSeq(9);        
			
			if(hasImaggCut(subImage))
				imageService.updateImageCut(subImage);				
			else { 
				  if(file10.getSize() > 0)
				  imageService.insertImageCut(subImage);
			  }
			
			subImage = new ImageCut();
	  if(file11.getSize() > 0 && id != 0){
		    name = Generator.generateFileName();
		    CommonUtil.writeImage(request, file11, Constants.DEFAULT_SUB_IMG_PATH, name);
			subImage.setImg(String.format(Constants.DEFAULT_SUB_URL, config.getHostAddress())+ name);
	  }
			
			subImage.setImgId(id);
			subImage.setX(request.getParameter("cutx10"));
			subImage.setY(request.getParameter("cuty10"));
			subImage.setxSize(request.getParameter("cutxSizex10"));
			subImage.setySize(request.getParameter("cutySizey10"));
			subImage.setSeq(10);   
			
			if(hasImaggCut(subImage))
				imageService.updateImageCut(subImage);				
			else{ 
				  if(file11.getSize() > 0)
					  imageService.insertImageCut(subImage);
				  }
			
		// 광고
		if(file.getSize() > 0 && !StringUtils.isNullOrEmpty(adImage.getAdName())){
			String name2 = Generator.generateFileName();
			CommonUtil.writeImage(request, file, Constants.DEFAULT_AD_IMG_PATH, name2);
			adImage.setImg(String.format(Constants.DEFAULT_AD_URL, config.getHostAddress()) + name2);
		
		}
		
		adImage.setImgId(id);
		adImage.setUserId(image.getUserId());
		if(adImage.getAdId() == 0)
			adImageService.insertAD(adImage);
		else
			adImageService.updateAD(adImage);		
		
		
	return "redirect:/admin/imageView.json?imgId="+image.getImgId();
	}
	
	
	private boolean hasImaggCut(ImageCut img){
		ImageCut i = imageService.getImageCut(img.getImgId(), img.getSeq());
		
		if(i == null)
			return false;
		else
			return true;
	}

}
